package com.jiandian.zh.api.auth.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

/**
 * 设置token存储在redis中
 *
 * @author lik
 */
@Configuration
public class TokenStoreConfig {
    @Autowired
    private RedisConnectionFactory redisConnectionFactory;

    @Value(value = "${zh.siteName}")
    private String siteName;

    @Bean
    public RedisTokenStore redisTokenStore() {
        RedisTokenStore redisTokenStore = new RedisTokenStore(redisConnectionFactory);
        // 用于区分每个网站的token
        String siteTokenPrefix = String.format("%s:" , siteName);
        redisTokenStore.setPrefix(siteTokenPrefix);
        return redisTokenStore;
    }
}
